﻿using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SW_SoftBully.Controllers;
using SW_SoftBully.Models.ModuloAdministracion.Banco;
using System.Data.SqlClient;
using log4net;

namespace SW_SoftBully.Models.ModuloAdministracion.Banco
{
    public class BancoDAO
    {
        public List<BancoBean> ListarBanco(BancoBean banco)
        {
            try
            {
                List<BancoBean> listaBanco = new List<BancoBean>();

                String cadenaConfiguracion = ConfigurationManager.ConnectionStrings["SoftBully"].ConnectionString;

                SqlConnection sqlCon = new SqlConnection(cadenaConfiguracion);

                sqlCon.Open();

                string commandString = "SELECT * FROM Banco WHERE estado = 1"; 

                SqlCommand sqlCmd = new SqlCommand(commandString, sqlCon);

                SqlDataReader dataReader = sqlCmd.ExecuteReader();

                while (dataReader.Read()){
                        BancoBean Banco = new BancoBean();
                        Banco.NombreComercial = Convert.ToString(dataReader["NombreComercial"]);
                        Banco.RazonSocial = Convert.ToString(dataReader["RazonSocial"]);
                        Banco.Estado = Convert.ToInt32(dataReader["Estado"]);
                        Banco.Id_Banco = Convert.ToInt32(dataReader["Id_Banco"]);
                        listaBanco.Add(Banco);                   
                }
                dataReader.Close();
                sqlCon.Close();

                return listaBanco;
            }
            catch (Exception e)
            {
                String men = e.ToString();
                banco.conexion = men;
                return null;
            }
        }
    }
}